package cn.t212.cloud.ms.client;

import cn.t212.cloud.ms.api.UserDTO;
import cn.t212.cloud.ms.api.UserServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class HelloController {
    @Autowired
    UserServiceClient userServiceClient;
    @Value("${user.name}")
    private String userName;

    @GetMapping("")
    public String callHello() {
        return userName + ":" + userServiceClient.hello();
    }
//    @Autowired private RestTemplate restTemplate;
//    @GetMapping("")
//    public String hello() {
//        System.out.println("最原始的方式（IP:PORT）调用8001的api");
//        return restTemplate.getForObject("http://localhost:8001",String.class);
//    }
//    @GetMapping("hello2")
//    public String hello2() {
//        System.out.println("通过eureka注册中心调用（微服务名称，并自带负载均衡）调用8001的api");
//        return restTemplate.getForObject("http://server-user-8001",String.class);
//    }
    @GetMapping("callUsers")
    public List<UserDTO> users(@RequestBody(required = false) UserDTO dto) {
        return userServiceClient.users(dto);
    }
}
